package cn.wenlihelp.service.impl;

import cn.wenlihelp.bean.Appeal;
import cn.wenlihelp.mapper.AppealMapper;
import cn.wenlihelp.service.AppealService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppealServiceImpl implements AppealService {
    @Resource
    private AppealMapper appealMapper;

    @Override
    public PageInfo<Appeal> findAll(int page, int limit, Appeal appeal) {
        PageHelper.startPage(page, limit);
        List<Appeal> appeals = appealMapper.findAll(appeal);
        return new PageInfo<>(appeals);
    }

    @Override
    public Appeal findById(Long id) {
        return appealMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean deleteByIds(Integer[] ids) {
        try {
            appealMapper.deleteByIds(ids);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean insert(Appeal appeal) {
        try {
            return appealMapper.insertSelective(appeal) > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean updateByPrimaryKey(Appeal appeal) {
        try {
            return appealMapper.updateByPrimaryKeySelective(appeal) > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
